package com.ruoyi.common.utils.poi.word.render.business;

import com.ruoyi.common.utils.poi.word.render.WordRenderHandler;
import org.springframework.stereotype.Component;

/**
 * 建议报告单
 */
@Component
public class T0101Handler extends WordRenderHandler {
    /*private ActivityPitfallRecord pitfallRecord;
    private ActivityPitfall activityPitfall;
    private Activity activity;
    @Autowired
    private ActivityPitfallMapper activityPitfallMapper;
    @Autowired
    private ActivityMapper activityMapper;
    @Override
    public void makeData() throws IOException {
        super.makeData();

        this.add("activityName", activity.getActivityName());
        this.add("fullAddress", pitfallRecord.getFullAddress());
        this.add("hazardUnit", pitfallRecord.getHazardUnit());
        this.add("industryField", pitfallRecord.getIndustryField());
        this.add("pitfallType", pitfallRecord.getPitfallType());
        this.add("pitfallLevel", pitfallRecord.getPitfallLevel());
        this.add("description", pitfallRecord.getDescription());
        this.add("judgmentBasis", pitfallRecord.getJudgmentBasis());
        //申请人

        List<Map> pitfallImgList = new ArrayList<>();
        String [] imgs = pitfallRecord.getImgs().split(",");
        for (int j = 0; j < imgs.length; j++) {
            String img = imgs[j];
            Map<String, Object> map = new HashMap<>();
            map.put("index", (j + 1) + "");
            File file = FileUploadUtils.urlToFile(img);
            BufferedImage image = ImgUtil.read(file);
            int minWidth = Math.min(image.getWidth(), 640);
            int minHeight = image.getHeight();
            if (image.getWidth() > 640) {
                minHeight = (int) (image.getHeight() * ((minWidth*1.0)/(image.getWidth()*1.0)));
            }
            map.put("img", Pictures.ofLocal(file.getAbsolutePath()).size(minWidth, minHeight).create() );
            pitfallImgList.add(map);
        }
        this.add("pitfallImgList", pitfallImgList);


    }

    @Override
    public void renderAfter() throws Exception {
        pitfallRecord.setReportPdfUrl(this.getPdfUrl());
        pitfallRecord.updateById();

    }

    @Override
    public void setObject(Object object) {
        super.setObject(object);
        pitfallRecord = (ActivityPitfallRecord) object;
        activityPitfall = activityPitfallMapper.selectById(pitfallRecord.getActivityPitfallId());
        activity = activityMapper.selectById(activityPitfall.getActivityId());
    }*/
}
